<?php
 /*****************************************************************************
 * editContact.php                                                            *
 * Last Modified: 2007-06-06                                                  *
 *                                                                            *
 * editContact.php outputs an HTML form populated with data from tblContacts  *
 * to be used to update the data stored in the contact record.                *
 *                                                                            *
 * BBG_Billing, a PHP application using MySQL for creating and maintaining a  *
 * contacts and invoices database.                                            *
 *                                                                            *
 * @copyright Copyright (C) 2007, Bugs Bee Gone Computer Services             *
 * @owner     Daniel Barnett (Bugs Bee Gone Computer Services)                *
 * @author    Daniel Barnett <dbarnett@bugsbeegone.com>                       *
 * @website   http://www.bugsbeegone.com                                      *
 * @license   http://www.gnu.org/licenses/gpl.html GNU General Public License *
 * @package   BBG_Billing                                                     *
 * @name      editContact.php                                                 *
 * @version   1.0.0                                                           *
 * @uses      Jpmaster77's Login Script (Written by: Jpmaster77, 2004-08-19)  *
 *             ->(http://www.evolt.org/PHP-Login-System-with-Admin-Features/) *
 *                                                                            *
 * This file is part of the "BBG_Billing" PHP application.                    *
 *                                                                            *
 * BBG_Billing is free software; you can redistribute it and/or modify        *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation; either version 2 of the License, or          *
 * (at your option) any later version.                                        *
 *                                                                            *
 * BBG_Billing is distributed in the hope that it will be useful,             *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with BBG_Billing; if not, write to the Free Software                 *
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
 *****************************************************************************/
 
 
  // Require session.php for use access control
	require "include/session.php";

  // If user is not logged in, redirect to main.php
	if(!$session->logged_in){
		header("Location: main.php");
		exit();
	}

  // Require config.inc.php for configuration variables
	require_once "config.inc.php";

  // Connect to MySQL
	mysql_connect($path, $username, $password);
	// Select database, if error die with error message
	@mysql_select_db($database) or die("Unable to select database.<br />" . mysql_error());

  // Get key value from URL
	$key = $_GET['key'];

  // Define MySQL query
	$query = "SELECT * FROM `tblContacts` WHERE `key`=$key LIMIT 1";

  // Execute MySQL query, if error die with error message
	$result = mysql_query($query) or die(mysql_error());

  // Determine number of rows returned
	$num = mysql_numrows($result);

  // Close connection
	mysql_close();

  // if num = 1...
	if($num == 1) {
    // Define data variables
		$key = mysql_result($result,0,"key");
		$customerID = mysql_result($result,0,"customerID");
		$company = mysql_result($result,0,"company");
		$firstName = mysql_result($result,0,"firstName");
		$lastName = mysql_result($result,0,"lastName");
		$address1 = mysql_result($result,0,"address1");
		$address2 = mysql_result($result,0,"address2");
		$city = mysql_result($result,0,"city");
		$state = mysql_result($result,0,"state");
		$zipCode = mysql_result($result,0,"zipCode");
		$phone1 = mysql_result($result,0,"phone1");
		$phone2 = mysql_result($result,0,"phone2");
		$fax = mysql_result($result,0,"fax");
		$email = mysql_result($result,0,"email");
		$webSite = mysql_result($result,0,"webSite");
		$notes = mysql_result($result,0,"notes");
  // If num != 1...
	} else {
    // Die with error message
		die('<p style="color: red;">Database error...<br />Record ID Not Found.</p><br />');
	}

  // Output data objects (using a POST form)
  echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
?>

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="ROBOTS" content="NOODP, NOFOLLOW" />
		<meta name="GOOGLEBOT" content="NOODP, NOFOLLOW" />
		<title>Bugs Bee Gone - Billing - Edit Contact</title>
		<meta name="description" content="Bugs Bee Gone - Billing - Edit Contact" />
		<meta name="keywords" content="php, mysql, test, practice" />
		<link rel="shortcut icon" href="" />
		<link href="contact.css" type="text/css" rel="stylesheet" />

		<script type="text/javascript" src="func.inc.js"></script>
	</head>

	<body>

	<div style="text-align: center;">
	<p>Update Record:</p>
	<form action="updateContact.php" method="post">
			<input type="hidden" name="key" value="<? echo $key; ?>" />
		<table width="500px" align="center" cellspacing="4" cellpadding="2">
		<tr>
			<td valign="top" width="150px">
				Customer ID:
			</td>

			<td valign="top">
				<input type="text" name="customerID" class="required" value="<? echo $customerID; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Company:
			</td>

			<td valign="top">
				<input type="text" name="company" value="<? echo $company; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				First Name:
			</td>

			<td valign="top">
				<input type="text" name="firstName" class="required" value="<? echo $firstName; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Last Name:
			</td>

			<td valign="top">
				<input type="text" name="lastName" class="required" value="<? echo $lastName; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Address:
			</td>

			<td valign="top">
				<input type="text" name="address1" class="required" value="<? echo $address1; ?>" /><br />
				<input type="text" name="address2" value="<? echo $address2; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				City:
			</td>

			<td valign="top">
				<input type="text" name="city" class="required" value="<? echo $city; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				State:
			</td>

			<td valign="top">
				<input type="text" name="state" class="required" value="<? echo $state; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Zip Code:
			</td>

			<td valign="top">
				<input type="text" name="zipCode" class="required" value="<? echo $zipCode; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Phone:
			</td>

			<td valign="top">
				<input type="text" name="phone1" class="required" value="<? echo $phone1; ?>" /><br />
				<input type="text" name="phone2" value="<? echo $phone2; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Fax:
			</td>

			<td valign="top">
				<input type="text" name="fax" value="<? echo $fax; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				E-Mail:
			</td>

			<td valign="top">
				<input type="text" name="email" value="<? echo $email; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Web Site:
			</td>

			<td valign="top">
				<input type="text" name="webSite" value="<? echo $webSite; ?>" />
			</td>
		</tr>

		<tr>
			<td valign="top" width="150px">
				Notes:
			</td>

			<td valign="top">
				<textarea name="notes" rows="3" id="notes" onkeypress="return checkMaxLength(event,this)" TAMaxLength="250" style="width:350px;"><? echo $notes; ?></textarea>
			</td>
		</tr>
		</table>

		<input type="Submit" value="Update Contact" /> <input type="button" onclick="cancel(this)" location="contacts.php" value="Cancel" />
		</form>
		</div>

	</body>
</html>
